function myfirstpage(){
	var a=jQ("#my_clipscontent a[enable!=0]")[0];
	if(typeof(a)=='undefined'){
		window.location.href=jQ("#ctxVal").val()+"/index.html";
	}else{
		window.location.href=jQ(a).attr("href");
	}
}

function checkExistUser(){
	var url="userAjax!checkExistUser.action";
	jQ.ajax({
		type: "POST",
		url:url,
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['loginflag']){
					jQ("#headtable_btnzone").show();
					var name=dataObj["name"];
					var url=dataObj.url;
					var uid=dataObj.uid;
					var usertype=dataObj.usertype;
					var sex=dataObj.sex;
					initUserInfo(name,url,uid,usertype,sex);
					jQ("#var_usertype").data("bgurl",url);
					jQ("#var_usertype").data("smallurl",dataObj.surl);
					jQ("#var_usertype").data("uid",dataObj.uid);
					jQ("#var_usertype").data("usertype",usertype);
					jQ("#var_usertype").data("username",name);
					jQ("#var_usertype").data("email",dataObj.email);
					var mobilenotice=dataObj.mobilenotice;
					jQ("#var_hasmobile").val(mobilenotice);
					if(usertype==2){
						jQ("#person_contacts").hide();
						jQ("#user_contacts").show();
						jQ("#head_search_box").hide();
						jQ("#my_clipscontent").addClass("cc");
						jQ("#my_clipscontent a.homepage").hide();
						jQ("#my_clipscontent a.homepage").attr("enable",0);
//						jQ("#my_clipscontent a.addclip").attr("enable",0);
					}else if(usertype==3){
						jQ("#var_usertype").data("noneuid",dataObj.uid);
						var hrefval=window.location.href;
						if(hrefval.indexOf("clip_detail.html")>=0){
							jQ("#headtable_btnzone").remove();
							jQ("#head_table div.head_center")
							.css({width:"900px",margin:"0 auto"})
							.append("<a href='"+jQ("#ctxVal").val()+"/clipsubscribe.html' class=\"simpletitle\">档期订阅</a>");
//							jQ("#user_avatar").css("background","url('"+url+"')");
//							jQ("#user_name").empty().append(name);
//							if(isNumber(sex)){
//								if(sex==1){
//									jQ("#user_sex").show().attr("title","男");
//								}else if(sex==2){
//									
//									jQ("#user_sex").addClass("female").show().attr("title","女");
//								}else{
//									jQ("#user_sex").hide();
//								}
//							}else{
//								jQ("#user_sex").hide();
//							}
						}
					}else{
						jQ("#message_tab li[mstype=request]").show();
						jQ("#user_contacts").hide();
						jQ("#person_contacts").show();
						jQ("#my_clipscontent").removeClass("cc");
						jQ("#my_clipscontent a.homepage").show();
						var hrefval=window.location.href;
						if(hrefval.indexOf("home.html")>=0){
							jQ("#user_avatar").css("background","url('"+url+"')");
							jQ("#user_name").empty().append(name);
							if(isNumber(sex)){
								if(sex==1){
									jQ("#user_sex").show().attr("title","男");
								}else if(sex==2){
									
									jQ("#user_sex").addClass("female").show().attr("title","女");
								}else{
									jQ("#user_sex").hide();
								}
							}else{
								jQ("#user_sex").hide();
							}
						}
					}
					var namehtml="";
					namehtml+="<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"'>"+name+"</a>";
					if(usertype==2)
						namehtml+="<span class='v_icon' title='档期认证'></span>";
					jQ("#person_name").empty().append(namehtml);
					setControlMenuBtn(usertype);
					var check=eval(dataObj.invitefriendnotice);
					if(check==null||typeof check=="undefined"){
						jQ("#findfinfo").hide();
					}else{
						if(check==0)
							jQ("#findfinfo").show();
					}
					jQ("div.login_box span.user_name").empty();
					if(usertype==2)
						jQ("div.login_box span.user_name").append("<b id=\"user_name\">"+dataObj["name"]+"</b><span class='v_icon'></span><b>"+dataObj["email"]+"</b>");
					else
						jQ("div.login_box span.user_name").append("<b id=\"user_name\">"+dataObj["name"]+"</b><b>"+dataObj["email"]+"</b>");
					jQ("div.login_box span.user_name").unbind("click").bind("click",function(){
						if(usertype==2)
							window.location.href=jQ("#ctxVal").val()+"/control/ccinfo.html";
						else
							window.location.href=jQ("#ctxVal").val()+"/control/userinfo.html";
					});
				}else{
					var hrefval=window.location.href;
					var list=jQ("#ctxVal").data("filterlist");
					var flag=false;
					for(var i=0;i<list.length;i++){
						if(hrefval.indexOf(list[i])>=0){
							flag=true;
							break;
						}
					}
					if(!flag)
						window.location.href=jQ("#ctxVal").val()+"/index.html";
					else{
						jQ("#headtable_btnzone").remove();
						if(hrefval.indexOf("user.html")>0){
							jQ("#head_table div.head_center")
							.css({width:"1230px",margin:"0 auto"})
							.append("<a href='"+jQ("#ctxVal").val()+"/clipsubscribe.html' class=\"simpletitle\">档期订阅</a>");
						}else{
							jQ("#head_table div.head_center")
							.css({width:"900px",margin:"0 auto"})
							.append("<a href='"+jQ("#ctxVal").val()+"/clipsubscribe.html' class=\"simpletitle\">档期订阅</a>");
						}
						
					}
				}
			}
		}
	});
}

function initUserInfo(name,url,uid,usertype,sex){
	if(jQ("#userinfo_head").length>0&&jQ("#userinfo_name").length>0){
		jQ("#userinfo_head").css("background","url('"+url+"')");
		var length=getWordsLength(name,14,1);
		if(length>90){
			jQ("#userinfo_name").addClass("limited");
		}else{
			jQ("#userinfo_name").removeClass("limited");
		}
		jQ("#userinfo_name").empty().append(name);
		jQ("#userinfo_head").attr("href",jQ("#ctxVal").val()+"/myclip/user.html?"+uid);
		jQ("#userinfo_name").attr("href",jQ("#ctxVal").val()+"/myclip/user.html?"+uid);
		if(usertype==2){
			jQ("#userinfo_name").after("<span class='v_icon' title='档期认证'></span>");
			jQ("#userinfo_name").css("margin-left","15px");
		}else if(usertype!=3){
			jQ("#userinfo_name").css("margin-left","10px");
			if(isNumber(sex)){
				if(sex==1){
					jQ("#user_sex").show().attr("title","男");
				}else if(sex==2){
					jQ("#user_sex").addClass("female").show().attr("title","女");
				}else{
					jQ("#user_sex").hide();
				}
			}else{
				jQ("#user_sex").hide();
			}
		}
	}
	
}

function setControlMenuBtn(usertype){
	if(usertype==1){
		jQ("#my_subscribes").show();
		jQ("#person_controlscontent a.personinfo").show();
		jQ("#person_controlscontent a.ccinfo").hide();
		jQ("#my_circlescontent a.contact_all").show();
		jQ("#my_circlescontent a.subscribed_all").hide();
		jQ("#my_circlescontent a.invite_friend").show();
		jQ("#my_circlescontent").css({"background":"url('"+jQ("#ctxVal").val()+"/image/headtable_detail_threeline.png')","height":"87px"});
	}else if(usertype==2){
		jQ("#my_subscribes").hide();
		jQ("#person_controlscontent a.personinfo").hide();
		jQ("#person_controlscontent a.ccinfo").show();
		jQ("#my_circles").hide();
		jQ("#cc_group").show();
		
	}
}

function removefindfinfo(){
	var url="userAjax!cancelInviteFriendNotice.action";
	jQ.ajax({
		type: "POST",
		url:url,
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['flag']){
					jQ("#findfinfo").hide();
				}else{
					window.location.href=jQ("#ctxVal").val()+"/index.html";
				}
			}
		}
	});
}

function logout(){
	jQ.ajax({
		type: "POST",
		url:"userAjax!logout.action",
		success:function(data){
			window.location.href=jQ("#ctxVal").val()+"/index.html";
		}
	});
}

function jalert(info,data,LFun){
	jQ("#ALERT").unbind();
	jQ("#ALERT p").html(info);
	if(LFun!=null)
		jQ("#ALERT").bind("LFun",data,LFun);
	jQ("#ALERT").parent().css('font', "14px \"Trebuchet MS\", sans-serif");
	jQ("#ALERT").dialog('open');
}

function clip_tips(info){
	jQ("#clip_tips p").empty().html(info);
	jQ("#clip_tips").parent().css('font', "14px \"Trebuchet MS\", sans-serif");
	jQ("#clip_tips").dialog('open');
}
function getMessageCount(){
	jQ.ajax({
		type : "POST",
		url : "messageAjax!getMsgCount.action",
		success : function(data){
			var count1 = eval(jQ(data).find("request").text());
			var count2 = eval(jQ(data).find("remind").text());
			var count3 = eval(jQ(data).find("systemmsg").text());
			var count4 = eval(jQ(data).find("comment").text());
			var count=0;
			if(eval(jQ("#var_usertype").val())==1)
				count=count1+count2+count3+count4;
			else
				count=count2+count3+count4;
			if(count==0){
				jQ("#messagebox span.countmsg").empty().hide();
				jQ("#messagebox span.countmsg").unbind("click");
			}else{
				var countstr;
				if(count>99){
					countstr="N";
				}else{
					countstr=""+count;
				}
				jQ("#messagebox span.countmsg").empty().append(countstr).show();
				jQ("#messagebox span.countmsg").unbind("click").bind("click",function(){
					window.location.href=jQ("#ctxVal").val()+"/box/message.html";
				});
			}
			var href=window.location.href;
			if(href.indexOf("message.html")>0){
				if(count1>0)
					jQ("#message_tab li.request").find("span.arrow_box").empty().append(count1).show();
				else
					jQ("#message_tab li.request").find("span.arrow_box").hide();
				if(count3>0)
					jQ("#message_tab li.systemmsg").find("span.arrow_box").empty().append(count3).show();
				else
					jQ("#message_tab li.systemmsg").find("span.arrow_box").hide();
				if(count4>0)
					jQ("#message_tab li.comment").find("span.arrow_box").empty().append(count4).show();
				else
					jQ("#message_tab li.comment").find("span.arrow_box").hide();
				if(count2>0)
					jQ("#message_tab li.remind").find("span.arrow_box").empty().append(count2).show();
				else
					jQ("#message_tab li.remind").find("span.arrow_box").hide();
			}
		}
	});
	setTimeout(getMessageCount,30000);
}

function initHeadButton(){
	/*
	jQ("#person_contacts").mouseover(function(){
		jQ(this).css({"backgroundPosition":"-239px -33px"});
	});
	jQ("#person_contacts").mouseout(function(){
		jQ(this).css({"backgroundPosition":"-239px 0px"});
	});
	*/
	jQ("#my_clips").mouseover(function(){
		jQ("#my_clipscontent").show();
		jQ("#my_clips a.btn").css({"backgroundPosition":"0px -25px"});
	});
	jQ("#my_clips").mouseout(function(){
		jQ("#my_clipscontent").hide();
		jQ("#my_clips a.btn").css({"backgroundPosition":"0px 0px"});
	});
	jQ("#my_subscribes").mouseover(function(){
//		jQ("#my_subscribescontent").show();
		jQ("#my_subscribes a.btn").css({"backgroundPosition":"-87px -25px"});
	});
	jQ("#my_subscribes").mouseout(function(){
//		jQ("#my_subscribescontent").hide();
		jQ("#my_subscribes a.btn").css({"backgroundPosition":"-87px 0px"});
	});
	jQ("#my_circles").mouseover(function(){
		jQ("#my_circlescontent").show();
		jQ("#my_circles a.btn").css({"backgroundPosition":"-174px -25px"});
	});
	jQ("#my_circles").mouseout(function(){
		jQ("#my_circlescontent").hide();
		jQ("#my_circles a.btn").css({"backgroundPosition":"-174px 0px"});
	});
	jQ("#cc_group").mouseover(function(){
		jQ("#cc_groupcontent").show();
		jQ("#cc_group a.btn").css({"backgroundPosition":"-261px -25px"});
	});
	jQ("#cc_group").mouseout(function(){
		jQ("#cc_groupcontent").hide();
		jQ("#cc_group a.btn").css({"backgroundPosition":"-261px 0px"});
	});
	jQ("#messagebox").mouseover(function(){
		jQ("#messageboxcontent").show();
		jQ("#messagebox a.btn").css({"backgroundPosition":"-435px -25px"});
	});
	jQ("#messagebox").mouseout(function(){
		jQ("#messageboxcontent").hide();
		jQ("#messagebox a.btn").css({"backgroundPosition":"-435px 0px"});
	});
	jQ("#person_controls").mouseover(function(){
		jQ("#person_controlscontent").show();
		jQ("#person_controls a.btn").css({"backgroundPosition":"-348px -25px"});
	});
	jQ("#person_controls").mouseout(function(){
		jQ("#person_controlscontent").hide();
		jQ("#person_controls a.btn").css({"backgroundPosition":"-348px 0px"});
	});
}

jQ(function(){
	var list=new Array("myclip/user.html","myclip/clip_detail.html");
	jQ("#ctxVal").data("filterlist",list);
	initHeadButton();
	var hrefval=window.location.href;
	if(hrefval.indexOf("clip_detail.html")>=0){
		
	}else
		checkExistUser();
	getMessageCount();
	initSearchInput();
	jQ("#addContact").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:true,
		width:420,
		zIndex:22222,
		buttons: {
			"确定": function() {
				jQ(this).dialog('close');
				addContact();
			},
			"取消": function() {
				jQ(this).dialog('close');
			}
		},
		close: function() {
		},
		open:function(){
		}
	});
	
	jQ("#backResults").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:true,
		width:420,
		zIndex:22222,
		buttons: {
			"确定": function() {
				jQ(this).dialog('close');
			}
		},
		close: function() {
		},
		open:function(){
		}
	});
	jQ("#ALERT").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		resizable:false,
		closeOnEscape:false,
		draggable:true,
		zIndex:22222,
		buttons: {
			"确定": function() {
				jQ(this).trigger("LFun");
				jQ(this).dialog('close');
			},
			"取消": function() {
				jQ(this).dialog('close');
			}
		},
		close: function() {},
		open:function(){}
	});
	
	jQ("#clip_tips").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		resizable:false,
		closeOnEscape:false,
		draggable:true,
		zIndex:22222,
		buttons: {
			"确定": function() {
				jQ(this).dialog('close');
			}
		}
	});
	
});

function initSearchInput(){
	jQ("#headsearchinput").focus(function(){
		if(jQ(this).hasClass("default")){
			jQ(this).removeClass("default").addClass("onit");
			jQ(this).val("");
		}
	});
	jQ("#headsearchinput").blur(function(){
		if(jQ(this).hasClass("onit")&&jQ.trim(jQ(this).val()).length==0){
			jQ(this).removeClass().addClass("default");
			jQ(this).val("搜索档期");
		}
	});
	jQ("#headsearchinput").next("a.btn").bind("click",function(){
		var inputobj=jQ(this).prev("input");
		var val=jQ.trim(inputobj.val());
		if(inputobj.hasClass("default")){
			inputobj.val("搜索档期");
			return;
		}else{
			inputobj.removeClass().addClass("default");
			inputobj.val("搜索档期");
		}
		var tm= encodeURI(val);
		var locationurl=window.location.href;
		var iscliplist=false;
		if(locationurl.indexOf("clip_search.html")>0){
			iscliplist=true;
		}
		if(iscliplist){
			jQ("#search_content").val(decodeURI(tm));
			loadMainpartRecords();
		}else{
			window.location.href=jQ("#ctxVal").val()+"/myclip/clip_search.html?content="+tm;
		}
	});
}

function HTMLEnCode(str) {
	var s = "";
	if (str.length == 0)
		return "";
	s = str.replace(/&/g, "&gt;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/    /g, "&nbsp;");
	s = s.replace(/\'/g, "&#39;");
	s = s.replace(/\"/g, "&quot;");
	s = s.replace(/\n/g, "<br>");
	return s;
}
function HTMLDeCode(str) {
	var s = "";
	if (str.length == 0)
		return "";
	s = str.replace(/&gt;/g, "&");
	s = s.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	s = s.replace(/&nbsp;/g, "    ");
	s = s.replace(/&#39;/g, "\'");
	s = s.replace(/&quot;/g, "\"");
	s = s.replace(/<br>/g, "\n");
	return s;
}

function getParameter(name){
    var paramStr=location.search;
    if(paramStr.length==0)return null;
    if(paramStr.charAt(0)!='?')return null;
    paramStr=unescape(paramStr);
    paramStr=paramStr.substring(1);
    if(paramStr.length==0)return null;
    var params=paramStr.split('&');
    var p = null;
    for(var i=0;i<params.length;i++){
        if(params[i].indexOf(name) >= 0){
            p = params[i].split('=');
            if(p[0]==jQ.trim(name))
            	p = p[1];
        }
    }
    return p;
}

function getUniqueParameter(){
    var paramStr=location.search;
    if(paramStr.length==0)return null;
    if(paramStr.charAt(0)!='?')return null;
    paramStr=unescape(paramStr);
    paramStr=paramStr.substring(1);
    if(paramStr.length==0)return null;
    return paramStr;
}

/**====加减时间的函数====**/
function htmlData(str){
	if(str==null||str.length==0)
		return "<i>暂无</i>";
	else{
		var tmp=jQ("#tools").text(str).html();
		jQ("#tools").empty();
		return tmp;
		
	}
}

function hourinput(event){
	var tar=jQ(event);
	var value=jQ.trim(tar.val());
	if(value.length>2){
		tar.val("0");
		return;
	}
	if(value==null||value.length<=0){
		tar.val("0");
		return;
	}
	if(isNumber(value)){
		if(eval(value)>23||eval(value)<0){
			tar.val("0");
		}else
			tar.val(eval(value));
	}else{
		tar.val("0");
	}
}

function hourminus(obj){
	var value=eval(jQ(obj).val());
	if(value<0){
		jQ(obj).val("23");
	}else{
		jQ(obj).val(--value);
	}
}

function autohourminusdown(obj){
	var autominusfun=setInterval(function(){
		var value=eval(jQ(obj).val());
		if(value==0){
			jQ(obj).val("23");
		}else{
			jQ(obj).val(--value);
		}
	},200);
	jQ(obj).data("autohourminus",autominusfun);
}

function autohourminusup(obj){
	var autominusfun=jQ(obj).data("autohourminus");
	clearInterval(autominusfun);
}

function autohourplusdown(obj){
	var autohourplus=setInterval(function(){
		var value=eval(jQ(obj).val());
		if(value==23){
			jQ(obj).val("0");
		}else{
			jQ(obj).val(++value);
		}
	},200);
	jQ(obj).data("autohourplus",autohourplus);
}

function autohourplusup(obj){
	var autohourplus=jQ(obj).data("autohourplus");
	clearInterval(autohourplus);
}


function hourplus(obj){
	var value=eval(jQ(obj).val());
	if(value>=23){
		jQ(obj).val("0");
	}else{
		jQ(obj).val(++value);
	}
}

function mininput(event){
	var tar=jQ(event);
	var value=jQ.trim(tar.val());
	if(value.length>2){
		tar.val("0");
		return;
	}
	if(value==null||value.length<=0){
		tar.val("0");
		return;
	}
	if(isNumber(value)){
		if(eval(value)>59||eval(value)<0){
			tar.val("0");
		}else
			tar.val(eval(value));
	}else{
		tar.val("0");
	}
}

function minminus(obj){
	var value=eval(jQ(obj).val());
	if(value<0){
		jQ(obj).val("59");
	}else{
		jQ(obj).val(--value);
	}
}

function minplus(obj){
	var value=eval(jQ(obj).val());
	if(value>=59){
		jQ(obj).val("0");
	}else{
		jQ(obj).val(++value);
	}
}


function autominminusdown(obj){
	var autominusfun=setInterval(function(){
		var value=eval(jQ(obj).val());
		if(value==0){
			jQ(obj).val("59");
		}else{
			jQ(obj).val(--value);
		}
	},200);
	jQ(obj).data("autominminus",autominusfun);
}

function autominminusup(obj){
	var autominusfun=jQ(obj).data("autominminus");
	clearInterval(autominusfun);
}

function autominplusdown(obj){
	var autominplus=setInterval(function(){
		var value=eval(jQ(obj).val());
		if(value==59){
			jQ(obj).val("0");
		}else{
			jQ(obj).val(++value);
		}
	},200);
	jQ(obj).data("autominplus",autominplus);
}

function autominplusup(obj){
	var autominplus=jQ(obj).data("autominplus");
	clearInterval(autominplus);
}



function activeBtnOnDialog(idstr,activeflag){
	var obj=jQ("#"+idstr);
	var closebtn=jQ("a.ui-dialog-titlebar-close");
	var bpane=obj.parent().find("div.ui-dialog-buttonpane");
	if(activeflag){
		bpane.show();
		closebtn.show();
	}else{
		bpane.hide();
		closebtn.hide();
	}
	
}

function init2weixinbox(shareid){
	var url="eventAjax!getDimensioncode.action";
	var a=1;
	jQ.ajax({
	   type: "GET",
	   url: url,
	   dataType: 'jsonp',
	   jsonp: 'jsonp_callback',
	   data: {
		   shareid:shareid
//		   a:a,
//		   title:title,
//		   url:detailurl,
//		   img:img,
//		   appid:""
	   },
	   success: function(msg){
	   }
	});
	
}

function errorShowWxBox(){
	clip_tips("档期不存在或已被删除");
	window.location.href=jQ("#ctxVal").val()+"/index.html";
}

function showWxBox(imgurl){
//	var imgsrc="https://open.weixin.qq.com/qr/get/"+msg+"/";
	jQ("#weinxinshare_img").attr("src",imgurl);
	jQ("#weinxinshare_interface").show();
}